package com.lee.crawler.gov.strategy;

import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;

import com.lee.crawler.gov.bean.CrawlerArticle;
import com.lee.crawler.gov.service.CrawlerArticleService;

public abstract class AbstractArticleStrategy implements ArticleStrategy {

	@Autowired
	private CrawlerArticleService crawlerArticleService;

	public void saveCrawlerArticle(String url) {
		Document detailContent = getContent(url);
		if (detailContent != null && detailContent.hasText()) {
			CrawlerArticle crawlerArticle = new CrawlerArticle();
			crawlerArticle.setTitle(getTitle(detailContent));
			crawlerArticle.setPublishedTime(getPublishedTime(detailContent));
			crawlerArticle.setContent(getContent(detailContent));
			crawlerArticle.setHtmlContent(getHtmlContent(detailContent));
			crawlerArticle.setSourceUrl(url);
			crawlerArticleService.insertTemplate(crawlerArticle);
		}
	}

}
